package com.ysj.demo.accompanynetwork.mvp.model;

import com.ysj.demo.accompanynetwork.ApiServiceUntil;
import com.ysj.demo.accompanynetwork.bean.FavouritePost;
import com.ysj.demo.accompanynetwork.bean.RestRsp;
import com.ysj.demo.accompanynetwork.mvp.common.OnCommonListener;
import com.ysj.demo.accompanynetwork.mvp.view.FollowView;
import com.ysj.demo.accompanynetwork.service.IFollowPostService;
import com.ysj.demo.accompanynetwork.service.bean.PostSearchModel;
import com.ysj.demo.accompanynetwork.service.bean.page.Page;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 关注的帖子
 */
public class FollowModel {

    private OnCommonListener onCommonListener;

    /**
     * 关注的帖子
     */
    public void list(PostSearchModel postSearchModel){
        Call<RestRsp<Page<FavouritePost>>> call = ApiServiceUntil.getInstance().getmApi().favouritePosts(postSearchModel);
        call.enqueue(new Callback<RestRsp<Page<FavouritePost>>>() {
            @Override
            public void onResponse(Call<RestRsp<Page<FavouritePost>>> call, Response<RestRsp<Page<FavouritePost>>> response) {
                onCommonListener.onSuccessListener(response.body());
            }

            @Override
            public void onFailure(Call<RestRsp<Page<FavouritePost>>> call, Throwable t) {
                onCommonListener.onFailListener(t);
            }
        });
    }


    public void unfollow(String id){
        FavouritePost favouritePost = new FavouritePost();
        favouritePost.setPostid(id);
        Call<RestRsp> call = ApiServiceUntil.getInstance().getmApi().unfollow(favouritePost);
        call.enqueue(new Callback<RestRsp>() {
            @Override
            public void onResponse(Call<RestRsp> call, Response<RestRsp> response) {
                onCommonListener.onSuccessListener(response);
            }

            @Override
            public void onFailure(Call<RestRsp> call, Throwable t) {
                onCommonListener.onFailListener(t);
            }
        });

    }

}
